import { createApp } from "vue";
import App from "./App.vue";
import project from "./project";
import { XPluginHost } from "x.host";
import { XComponentPlugin } from "x.common";

export class XHelp extends XComponentPlugin {
    constructor() {
        super("x.web/help", project.version, project.name, App);
    }
    onHostInit(): void {
        let home = this.host!.plugins.find((p) => p.name == "x.web/home");
        if (home) {
            this.init();
        } else {
            this.host!.on("plugin-init", (p) => {
                if (p.name == "x.web/home") {
                    this.init();
                }
            });
        }
    }
    init() {
        let el = document.createElement("div");
        el.className = "x-plugin";
        createApp(App, { plugin: this }).mount(el);
        this.host!.dom!.appendChild(el);

        let homeBox = document.querySelector(".x-home .home-box")!;
        homeBox.appendChild(el.querySelector(".x-help .help-box")!);
    }
}

new XHelp();
